//
//  ZhujiaoListController.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/12/20.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "ZhujiaoListController.h"
#import "ZhujiaoCell.h"
#import "SignInViewController.h"
#import "ZhujiaoNetwork.h"
#import "SZLAccountHelper.h"
#import "MBProgressHUD+MJ.h"

@interface ZhujiaoListController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *sources;

@end

@implementation ZhujiaoListController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"助教管理";
    [self.view addSubview:self.tableView];
    [self getTeachList];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.sources.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZhujiaoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZhujiaoCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.sources[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SignInViewController *vc = [[SignInViewController alloc]init];
    vc.model = self.sources[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)getTeachList
{
    NSMutableDictionary *parame = [NSMutableDictionary dictionary];
    parame[@"token"] = [SZLAccountHelper shareInstance].token;
    [self showClearBgWaiter];
    [ZhujiaoNetwork getZhujiaoActivityListWithParame:parame response:^(BOOL success, NSString *msg, NSArray *lists) {
        [self hideWaiter];
        if (success) {
            [self.sources addObjectsFromArray:lists];
            [self.tableView reloadData];
        }else {
            [MBProgressHUD showError:msg];
        }
    }];
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64)];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZhujiaoCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([[ZhujiaoCell class] class])];
        _tableView.rowHeight = 80;
        _tableView.tableFooterView = [[UIView alloc]init];
    }
    return _tableView;
}
- (NSMutableArray *)sources
{
    if (!_sources) {
        _sources = [NSMutableArray array];
    }
    return _sources;
}

@end
